import java.util.HashMap;
import java.util.Map;

public class 力扣两数之和 {

        public static  int[] twoSum(int[] nums, int target) {
            int len = nums.length;
            Map<Integer,Integer> hashMap = new HashMap<>(len-1);
            hashMap.put(nums[0],0);
            for(int i=0;i<len;i++) {
                if(hashMap.containsKey(target-nums[i])) {
                    return new int[]{i,hashMap.get(target-nums[i])};
                }
                hashMap.put(nums[i],i);
            }
            return new int[]{0,0};
        }
    public static void main(String[] args) {
        int[] arr = {1,2,3,4,5,6,7,8};
        int n = 9;
        twoSum(arr,n);
    }
}
